pre_src_prepare() {
  #src: https://wiki.gentoo.org/wiki//etc/portage/patches
  [[ ${EAPI:-0} == [012345] ]] || return #https://bugs.gentoo.org/show_bug.cgi?id=575704
  local ec=-1
  if ! type epatch_user > /dev/null 2>&1; then
#    local names="epatch_user epatch evar_push evar_push_set evar_pop estack_push estack_pop"
#    set -evx
#    source <(awk "/^# @FUNCTION: / { p = 0 } /^# @FUNCTION: (${names// /|})\$/ { p = 1; } p { print  }" /usr/portage/eclass/eutils.eclass)
    local names="EPATCH_USER_SOURCE epatch_user epatch evar_push evar_push_set evar_pop estack_push estack_pop"
    source <(awk "/^# @(FUNCTION|VARIABLE): / { p = 0 } /^# @(FUNCTION|VARIABLE): (${names// /|})\$/ { p = 1 } p { print }" ${PORTDIR}/eclass/eutils.eclass)

    epatch_user
    ec="$?"
#    set +evx

    for name in $names; do
      unset $name
    done
  else
    epatch_user
    ec="$?"
  fi

  if test "$ec" -ne "0"; then #TODO: test for 0,1 and 2 see: /usr/portage/eclass/eutils.eclass
    if test "$ec" -eq "2"; then
      ewarn "USER PATCHES already APPLIED by ebuild, above!"
    else
      if test "$ec" -eq "1"; then
        ewarn "NO USER PATCHES APPLIED!!!"
      else
        ewarn "epatch_user - unknown exit code: $ec  probably NO PATCHES APPLIED"
      fi
    fi
  else
    ewarn "user patches applied"
  fi


  #unset DEBUG for packages known to break.
  if test "$PN" = "gsm" -o "$PN" = "libunique"; then
    unset DEBUG
  fi
  #TODO: make a more general thing here, like package.env is, but this one is for overriding even existing env. vars
  #set >/tmp/set.txt
}


